﻿using BCCommon;
using BlackCoffeeRESTful.Configs;
using Microsoft.AspNetCore.Mvc;
using System;
using BCDto.OA.PunchEdits;
using BCService.OA.PunchEdits;

namespace BlackCoffeeRESTful.Controllers.Management.OA
{
    /// <summary>
    /// 打卡服务接口
    /// </summary>
    [ApiExplorerSettings(GroupName = "OAAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class PunchEditsController : ManagementBaseController
    {
        private readonly IPunchEditsService punchEditsService;

        public PunchEditsController(IPunchEditsService punchEditsService)
        {
            this.punchEditsService = punchEditsService;
        }

        #region 创建一条打卡信息
        /// <summary>
        /// 创建一条打卡信息
        /// </summary>
        /// <param name="punchEditsRequestDto">打卡创建请求模型</param>
        /// <response code="200">新创建的打卡信息</response>
        /// <returns></returns>
        [HttpPost]
        [Log("创建一条打卡信息")]
        [ProducesResponseType(typeof( PunchEditsDto), 200)]
        public IActionResult Post([FromBody] PunchEditsRequestDto punchEditsRequestDto)
        {

            return Ok(this.punchEditsService.Create(this.Admin, punchEditsRequestDto));
        }
        #endregion

        #region 修改一条打卡信息

        /// <summary>
        /// 修改打卡信息
        /// </summary>
        /// <param name="punchEditsNo">打卡Id</param>
        /// <param name="punchEditsSimPutDto">打卡修改请求模型</param>        
        /// <returns></returns>
        /// <response code="200">修改后的打卡信息。</response>
        [HttpPut("{punch_edits_no}")]
        [Log("修改打卡信息")]
        [ProducesResponseType(typeof( PunchEditsDto), 200)]
        public IActionResult Put([FromRoute(Name = "punch_edits_no")] string punchEditsNo, [FromBody]  PunchEditsSimPutDto  punchEditsSimPutDto)
        {

            return this.Ok(this.punchEditsService.Update(punchEditsNo, punchEditsSimPutDto));
        }

        #endregion

        #region 删除一条打卡信息
        /// <summary>
        /// 删除一条打卡信息
        /// </summary>
        /// <param name="punchEditsNo">打卡Id</param>
        /// <returns></returns>
        /// <response code="204">刪除一条打卡信息成功。</response>
        [HttpDelete("{punch_edits_no}")]
        [Log("删除一条打卡信息")]
        public IActionResult Delete([FromRoute(Name = "punch_edits_no")]string punchEditsNo)
        {
            this.punchEditsService.Delete(punchEditsNo);
            return NoContent();
        }
        #endregion

        #region 获取一条打卡信息
        /// <summary>
        /// 获取一条打卡信息
        /// </summary>
        /// <param name=" punchEditsNo">打卡ID</param>
        /// <returns></returns>
        [HttpGet("{punch_edits_no}")]
        [ProducesResponseType(typeof(PunchEditsDto), 200)]

        public IActionResult Get([FromRoute(Name = "punch_edits_no")] string punchEditsNo)
        {
            return Ok(this.punchEditsService.Get(punchEditsNo));
        }

        #endregion

        #region 获取打卡信息接口（分页）
        /// <summary>
        /// 获取打卡信息列表（分页）
        /// </summary>
        /// <param name="adminFullName">员工姓名</param>
        /// <param name="idCard">身份证</param>
        /// <param name="phone">手机号</param>
        /// <param name="adminId">员工ID</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>       
        /// <param name="ascending">排序</param>
        /// <param name="pageIndex">以 1 起始的页码 (默认 1)。</param>
        /// <param name="pageSize">每页要显示的行数 (默认 10)。</param>
        /// <response code="200">带有分页信息的打卡信息列表。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<PunchEditsInfoDto>), 200)]
        public IActionResult List([FromQuery(Name = "user_name")] string adminFullName,
            [FromQuery(Name = "id_card")] string idCard,
            [FromQuery(Name = "phone")] string phone,
            [FromQuery(Name = "admin_id")] long? adminId,
            [FromQuery(Name = "start")] DateTime? start,
            [FromQuery(Name = "end")] DateTime? end,
            [FromQuery(Name = "ascending")] bool? ascending,
            int pageIndex = 1,
            int pageSize = 10)
        {
            var list = this.punchEditsService.List(adminFullName, idCard, phone, adminId, start, end, ascending, pageIndex, pageSize);
            return this.Ok(list);

        }
        #endregion
    }
}